package battle;
import java.io.IOException;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.interceptor.ServletRequestAware;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ModelDriven;

import entity.CardVo;


public class BattleAction implements Action,ModelDriven<CardVo>,ServletRequestAware {

	private BattleService battleService=new BattleService();
	private HttpServletRequest request;
    
    public void setServletRequest(HttpServletRequest request){
    	this.request = request;
    }
    @Override
	public CardVo getModel() {		
		return null;
	}

	@Override
	public String execute() throws Exception {		
		return null;
	}
	private String npcCardIds;
	private String playerCardIds;
	

	public void setNpcCardIds(String npcCardIds) {
		this.npcCardIds = npcCardIds;
	}

	public void setPlayerCardIds(String playerCardIds) {
		this.playerCardIds = playerCardIds;
	}
	public String getBattleCards(){
		BattleDao dao=new BattleDao();
		List<CardVo> list=dao.getCardList();
		List<CardVo> npc=battleService.getNpcCards(list);
		list=dao.getCardList();
		List<CardVo> player=battleService.getPlayerCards(list);				       
		
		request.setAttribute("npc", npc);
		request.setAttribute("player", player);

		return SUCCESS;
	}
	
	public void battle() throws IOException{
		HttpServletResponse response = ServletActionContext.getResponse();
		response.setCharacterEncoding("UTF-8");
		System.out.println(playerCardIds);
		String info="[function(){$(\"#0\").animate({marginLeft:'-=50px',height:'+=100px',width:'+=100px'},200,shownext);}," +
				"function(){$(\"#0\").animate({marginLeft:'+=50px',height : '-=100px',width : '-=100px'}, 200, shownext);},]";
		
		response.getWriter().write(info);
		
	}
	
}


